package com.dimld.connect.http;

import com.dimld.connect.ConnectContainer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Timer;
import java.util.TimerTask;

class ClearTask extends TimerTask {
    private final Logger     log = LoggerFactory.getLogger(getClass());
    private final Timer      timer;
    private final HttpHandle ea;
    private final String     thName;
    private final HttpHandle httpHandle;

    public ClearTask(Timer timer, HttpHandle ea, String name, HttpHandle hh) {
        this.timer = timer;
        this.ea = ea;
        this.thName = name;
        this.httpHandle = hh;
    }

    public void run() {
        this.log.warn("ThreadName[" + this.thName + "]ִtimeout");
        this.timer.cancel();
        this.ea.shutdown();
        this.httpHandle.setState(false);
        if (this.httpHandle.getReader() != null) {
            this.httpHandle.getReader().disconnect(this.httpHandle);
        }
        ConnectContainer.remove(this.httpHandle.getUuid());
    }
}